package com.fc.hkx.process.migrate;

import java.io.File;
import java.io.FileFilter;
import java.util.regex.Matcher;

/**
 * filters out all the files which are between two versions.
 */
public class VersionBetweenFileFilter implements FileFilter {
    
    private int _version;
    private int _lower;
    
    /**
     * create's this filter, returning everything SMALLER than the
     * current version, but GREATER OR EQUAL to the lower version.
     * 
     * @param currentVersion
     */
    public VersionBetweenFileFilter( int currentVersion, int lowerVersion ) {
        _version = currentVersion;
        _lower = lowerVersion;
    }

    /**
     * returns true if it's a file filter
     */
    @Override
    public boolean accept(File file) {
        Matcher matcher = VersionedStringComparator.STRING_PATTERN.matcher(file.getName());
        return (matcher.matches() && Integer.parseInt(matcher.group(1)) <= _version && Integer.parseInt(matcher.group(1)) > _lower);
    }

}
